package com.example.baiduapi.Controller;

import com.example.baiduapi.domain.emnu.PageEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.Random;

@Slf4j
@Controller
public class PageController {
    @GetMapping("/home")
    public String Home(){
        String url = generateCacheBustedUrl(PageEnum.LOGIN.value);
        return "redirect:"+url;
    }
    @GetMapping("/index")
    public String index(){
        String url = generateCacheBustedUrl(PageEnum.LOGIN.value);
        return "redirect:"+url;
    }
    @GetMapping("/")
    public String defalut(HttpServletRequest request){
        System.out.println("请求对象："+request);
        StringBuffer requersURL = request.getRequestURL();
        System.out.println(requersURL.toString());
        return "redirect:"+PageEnum.DOWNLOAD_APP.value;
    }
    public static String generateCacheBustedUrl(String url) {
        // 生成随机数作为参数
        Random random = new Random();
        int randomNumber = random.nextInt(100000);  // 在这里可以自定义随机数的范围

        // 将随机数作为参数拼接到URL后面
        String cacheBustedUrl = url + "?v=" + randomNumber;
        return cacheBustedUrl;
    }
}
